//
//  PressableEffectButton.swift
//  Chatup
//
//  Created by iron man on 2023/12/11.
//

import SwiftUI

struct PressableEffectButton<Label>: View where Label : View{
    var action: () -> Void
    var label: () -> Label
    @State private var isPressed = false

    var body: some View {
        Button(action: {
            self.isPressed = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                self.isPressed = false
                feedback()
                self.action()
            }
        }) {
            label()
        }
        .scaleEffect(isPressed ? 0.95 : 1.0)
        .animation(.easeInOut(duration: 0.05), value: isPressed)
    }
    
    func feedback() {
         
            let generator = UIImpactFeedbackGenerator(style: .medium)
           
            generator.prepare()

            generator.impactOccurred()
        }
}

